package com.zx._12_算法.剑指offer._2022;

import java.util.HashSet;

/**
 * https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/
 */
public class 扑克牌中的顺子 {

    public static void main(String[] args) {
        isStraight(new int[]{0, 0, 1, 2, 5});
    }

    public static boolean isStraight(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        int min = 1;
        int max = 1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                continue;
            }

            if (set.contains(nums[i])) {
                return false;
            }
            set.add(nums[i]);

            if (nums[i] > max) {
                max = nums[i];
            }
            if (nums[i] < min) {
                min = nums[i];
            }
        }
        return max - min <= 4;
    }
}
